<?php

/**
 * comment actions.
 *
 * @package    Nika
 * @subpackage comment
 * @author     Alexey Shapran (alexey.shapran@gmail.com)
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class commentActions extends sfActions
{
	/**
	 * Executes index action
	 *
	 * @param sfRequest $request A request object
	 */
	public function executeIndex(sfWebRequest $request)
	{
	}

	public function executeSubmit(sfWebRequest $request)
	{
		$this->forward404Unless($request->isMethod('post'));
		$comm = new Comment();
		$comm->entity_id = $request->getParameter('entity_id');
		$comm->entity_type = $request->getParameter('entity_type');
		$comm->body = strip_tags($request->getParameter('body'));
		$comm->user_id = $this->getUser()->getGuardUser()->getId();
		$comm->save();
		
		return $this->renderText($comm['id']);
		
		//serialize(array('comment_id'=>$comm->getId()));
		//$fromwhere = $_SERVER["HTTP_REFERER"];
		//$this->redirect($fromwhere);
	}
	public function executeDelete(sfWebRequest $request)
	{
		$comid = $request->getParameter('comid');
		$uid = $this->getUser()->getGuardUser()->getId();		
		Comment::deletecommentbyidanduserid($comid, $uid);
			
		return sfView::NONE;
	}
	public function executeDeletefromindex(sfWebRequest $request)
	{
		$pictid = $request->getParameter('photoid');		
		$picture = Media::retrieveUserIdByMediaFileId($pictid);		
				
		$this->forward404Unless( $this->getUser()->getGuardUser()->getId() == $picture['user_id'] );
		
		$comid = $request->getParameter('comid');
		Comment::deletecommentbyid($comid);
		$fromwhere = $_SERVER['HTTP_REFERER'];
		$this->redirect($fromwhere);
				
	}
}
